<?php

namespace app\api\behavior;


use addons\wanlshop\library\WanlPay\WanlPay;
use app\admin\model\User;
use app\common\controller\Api;
use app\common\model\FinanceLog;

class UserLog
{
    public function run()
    {
        $pay = new WanlPay;

        $user_ids = FinanceLog::where('createtime','<',time()-30*86400)
            ->where('type','pay')->column('user_id');

        foreach ($user_ids as $k=>$v){
            $user = User::where(['id'=>$v])->field('id,finance')->find();
            if ($user){
                if ($user->finance>0){
                    $pay->finance(-$user->finance, $v, '消费金一个月未使用自动清除', 'expired');
                }

            }

        }
    }
}
